package Logic;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Database.AuditLogDB;

/**
 * Servlet implementation class AppointmentDelete_BLL
 */

public class CommitteeDelete_BLL extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CommitteeDelete_BLL() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (request.getParameter("submit").equals("Confirm Delete")) {
			String id = request.getParameter("id");

			if (id != null && !id.equals("")) {
				Database.CommitteeRoleDB.deleteCommitteeRole(id);
				Database.CommitteeDB.deleteCommittee(id);
				AuditLogDB.insertLog("delete committee", (String) request
						.getSession().getAttribute("name"));
			}
			response.sendRedirect("committee_viewcomm.jsp?error=-1");
		} else {
			if (request.getParameter("search").equals("true")) {
				request.setAttribute("id",  request.getParameter("id"));
				request.getRequestDispatcher("committee_searchresult.jsp")
						.forward(request, response);
			} else {
				response.sendRedirect("committee_viewcomm.jsp");
			}
		}
	}
}
